package com.jymj.service.impl;

import com.jymj.dao.YlDao;
import com.jymj.entity.*;
import com.jymj.entity.dto.RenovatedDto;
import com.jymj.service.YlService;
import com.jymj.utils.RRException;
import com.jymj.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Transactional
@PropertySource("classpath:/config/filePath.properties")
public class YlServiceImpl implements YlService {

    @Autowired
    private YlDao ylDao;

    @Override
    public YlEntity queryByPoint(String point, Integer pjid) {
        return ylDao.queryByPoint(point, pjid);
    }

    @Override
    public List<YlEntity> queryList(Map<String, Object> params) {
        return ylDao.queryList(params);
    }

    @Override
    public int queryTotal(Map<String, Object> params) {
        return ylDao.queryTotal(params);
    }

    @Override
    public YlEntity getYLbyId(Integer objectid, String cunName) {
        YlEntity ylEntity = new YlEntity();
        ylEntity.setObjectid(objectid);
        if (cunName != null && !cunName.equals("")) {
            ylEntity.setXzqmc(cunName);
        }
        return ylDao.getYLbyId(ylEntity);
    }

    @Override
    public Map getDiQuery(Integer pageSize, Integer currPage, YlEntity ylEntity, String code) {
        Map map = new HashMap();
        int allCount = 0;
        List<YlEntity> ylEntityList;
        Map map1 = new HashMap();
        if (pageSize != null && currPage != null) {
            map1.put("pageSize", pageSize);
            map1.put("currPage", currPage);
            map1.put("ylEntity", ylEntity);
            map1.put("code", code);
            ylEntityList = ylDao.getDiQuery(map1);
        } else {
            map1.put("ylEntity", ylEntity);
            map1.put("code", code);
            ylEntityList = ylDao.getDiQueryExcel(map1);
        }
        allCount = getAppDiCounnt(ylEntity, code);
        ylEntityList.removeAll(Collections.singleton(null));
        map.put("ylEntityList", ylEntityList);
        map.put("allCount", allCount);
        return map;
    }

    @Override
    public int getAppDiCounnt(YlEntity ylEntity, String code) {
        Map map = new HashMap();
        map.put("ylEntity", ylEntity);
        map.put("code", code);
        return ylDao.getAppDiCounnt(map);
    }

    @Override
    public YlEntity getYLbyPoint(String point, String code) {
        Map<String, Object> map = new HashMap<>();
        if (point != null) {
            map.put("point", point);
        }
        map.put("code", code);
        YlEntity ylEntity = ylDao.getYLbyPoint(map);
        return ylEntity;
    }

    @Override
    public List<KeyValueEntity> getAppDiQsxz(YlEntity ylEntity, String code) {
        Map map = new HashMap();
        map.put("ylEntity", ylEntity);
        map.put("code", code);
        return ylDao.getAppDiQsxz(map);
    }

    @Override
    public List<KeyValueEntity> getAppDiSyqlx(YlEntity ylEntity, String code) {
        Map map = new HashMap();
        map.put("ylEntity", ylEntity);
        map.put("code", code);
        return ylDao.getAppDiSyqlx(map);
    }

    @Override
    public List<KeyValueEntity> getAppDiCqly(YlEntity ylEntity, String code) {
        Map map = new HashMap();
        map.put("ylEntity", ylEntity);
        map.put("code", code);
        return ylDao.getAppDiCqly(map);
    }

    @Override
    public List<KeyValueEntity> getZhaiAreaByFrame(String points, String code) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        return ylDao.getZhaiAreaByFrame(map);
    }

    @Override
    public List<YlEntity> getYlList(Map map) {
        return ylDao.getYlList(map);
    }

    @Override
    public Integer getYlListCount(String points, String code, List ylTypeList) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        map.put("ylTypeList", ylTypeList);
        return ylDao.getYlListCount(map);
    }

    @Override
    public List<YlEntity> getYlListExcel(Map map) {
        return ylDao.getYlListExcel(map);
    }

    @Override
    public void updateYl(YlEntity ylEntity) {
        ylDao.saveYlEntity(ylEntity);
    }

    @Override
    public void updateYlBatch(Integer[] ylIds) {
        ylDao.updateYlBatch(ylIds);
    }

    @Override
    public void updateYlByAppId(Integer appId) {
        ylDao.updateYlByAppId(appId);
    }

    @Override
    public List<KeyValueEntity> queryAppSummary(List xzqmcList, String code) {
        Map map = new HashMap();
        map.put("xzqmcList", xzqmcList);
        map.put("code", code);
        return ylDao.queryAppSummary(map);
    }


    @Override
    public List<YlEntity> queryYl(String geom) {
        return ylDao.queryYl(geom);
    }

    @Override
    public void save(YlEntity ylEntity) {
        ylDao.save(ylEntity);
    }

    @Override
    public void deleteByObjectid(Integer ylId) {
        ylDao.deleteByObjectid(ylId);
    }


    @Override
    public YlEntity queryByGid(Integer gid) {
        return ylDao.queryByGid(Long.valueOf(gid));
    }

    @Override
    public void updateAppTYpe(Integer ylId) {
        ylDao.updateAppTYpe(ylId);
    }

}
